package com.springboot.personblogsystem.common;

import lombok.Data;

import java.io.Serializable;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2025-05-14
 * Time: 8:55
 */
@Data
public class Result<T> implements Serializable {
    private ResultCodeEnum resultCodeEnum;
    private String message;
    private T data;

    private Result(ResultCodeEnum resultCodeEnum, String message, T data) {
        this.resultCodeEnum = resultCodeEnum;
        this.message = message;
        this.data = data;
    }

    private Result() {}

    // 创建具体实例
    public static <T> Result<T> success() {
        return new Result<>(ResultCodeEnum.SUCCESS, "", null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultCodeEnum.SUCCESS, "", data);
    }

    public static <T> Result<T> error(String message) {
        return new Result<>(ResultCodeEnum.ERROR, message, null);
    }

    public static <T> Result<T> error(String message, T data) {
        return new Result<>(ResultCodeEnum.ERROR, message, data);
    }

    public static <T> Result<T> fatal(String message, T data) {
        return new Result<>(ResultCodeEnum.FATAL, message, data);
    }

}
